<html>
<head><meta charset="utf-8"><title>Bound checks abort · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html">Bound checks abort</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="175517084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175517084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175517084">(Sep 12 2019 at 10:42)</a>:</h4>
<p>Why do bound checks panic instead of aborting ?</p>



<a name="175517745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175517745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175517745">(Sep 12 2019 at 10:56)</a>:</h4>
<p>Why pick out bounds checks? You could just as well ask the same for most programming errors (~= sources of panics), right?</p>



<a name="175518715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175518715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175518715">(Sep 12 2019 at 11:11)</a>:</h4>
<p>Well an access out-of-bounds is a classic instance of undefined behavior in C</p>



<a name="175518774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175518774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175518774">(Sep 12 2019 at 11:12)</a>:</h4>
<p>So the minimal solution to avoid this undefined behavior would be to just abort the process, as opposed to doing something more complex, like unwinding</p>



<a name="175518793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175518793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175518793">(Sep 12 2019 at 11:12)</a>:</h4>
<p>Other sources of panics, like OOM, aren't necessary due to undefined behavior</p>



<a name="175519025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519025">(Sep 12 2019 at 11:17)</a>:</h4>
<p>For context, I was looking at how we implement the bound checks: <a href="https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/panicking.rs#L55" target="_blank" title="https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/panicking.rs#L55">https://github.com/rust-lang/rust/blob/316a391dcb7d66dc25f1f9a4ec9d368ef7615005/src/libcore/panicking.rs#L55</a></p>



<a name="175519223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519223">(Sep 12 2019 at 11:21)</a>:</h4>
<p>There appears to be a libcore feature that does just that</p>



<a name="175519923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519923">(Sep 12 2019 at 11:33)</a>:</h4>
<p>you can turn all panics into aborts</p>



<a name="175519929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519929">(Sep 12 2019 at 11:33)</a>:</h4>
<p>not sure if you can turn just some of them</p>



<a name="175519993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519993">(Sep 12 2019 at 11:34)</a>:</h4>
<p>the reason some of them are panics is that things like servo want each tab to fail in the worst case via a panic</p>



<a name="175519998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175519998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175519998">(Sep 12 2019 at 11:34)</a>:</h4>
<p>instead of terminating the entire browser</p>



<a name="175520911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175520911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175520911">(Sep 12 2019 at 11:48)</a>:</h4>
<p>Yes the libcore feature applies to all panics</p>



<a name="175521854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175521854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175521854">(Sep 12 2019 at 12:02)</a>:</h4>
<p>Turning them into aborts does not make a big difference code-size wise</p>



<a name="175521866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175521866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175521866">(Sep 12 2019 at 12:03)</a>:</h4>
<p>That libcore feature makes quite a difference</p>



<a name="175521873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175521873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175521873">(Sep 12 2019 at 12:03)</a>:</h4>
<p>TIL</p>



<a name="175522624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175522624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175522624">(Sep 12 2019 at 12:14)</a>:</h4>
<blockquote>
<p>Well an access out-of-bounds is a classic instance of undefined behavior in C</p>
</blockquote>
<p>This seems to come from a perspective that's entirely alien to me. Rust isn't "C with the UB papered over minimally", it's its own language with its own design decisions. Signed int overflow is also UB in C, but Rust alternatively makes it defined or panic instead of aborting.</p>



<a name="175523126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523126">(Sep 12 2019 at 12:21)</a>:</h4>
<p>I wasn't suggesting that Rust is C. I was wondering why the particular trade-off of panicking was picked up for this.</p>



<a name="175523228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523228">(Sep 12 2019 at 12:23)</a>:</h4>
<p>The difference between <code>-C panic=abort</code>/<code>-C panic=unwind</code> and <code>libcore+panic_immediate_abort</code> is quite large</p>



<a name="175523243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523243">(Sep 12 2019 at 12:23)</a>:</h4>
<p>A reasonable question, I'm just mildly confused by the C reference if the was the point you wanted to make, as it's entirely unrelated.</p>



<a name="175523264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523264">(Sep 12 2019 at 12:23)</a>:</h4>
<p>I wouldn't know how to actually implement a panic runtime that behaves like <code>panic_immediate_abort</code></p>



<a name="175523334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523334">(Sep 12 2019 at 12:24)</a>:</h4>
<p>Probably most of the code size difference is in not needing the panic message (assuming LTO or if you're only measuring libcore code size)</p>



<a name="175523382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523382">(Sep 12 2019 at 12:25)</a>:</h4>
<p>Yes, I think it might suffice to allow users to specify whether their panic hooks should be inline or not.</p>



<a name="175523437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523437">(Sep 12 2019 at 12:26)</a>:</h4>
<p>I don't follow</p>



<a name="175523495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523495">(Sep 12 2019 at 12:27)</a>:</h4>
<p>When calling the core::panic:: APIs that panic, the panic message formatting is implemented within them, most of the message is only stored once per binary</p>



<a name="175523532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523532">(Sep 12 2019 at 12:28)</a>:</h4>
<p>On the call site, we store the line number as a string in static memory</p>



<a name="175523593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523593">(Sep 12 2019 at 12:28)</a>:</h4>
<p>since the panic methods are <code>#[inline(never)]</code>, an implementation that would just <code>abort</code> without printing anything would still contain that (line number, file name, passing those to the call, etc.)</p>



<a name="175523614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523614">(Sep 12 2019 at 12:29)</a>:</h4>
<p>What <code>panic_immediate_abort</code> does is it makes these methods in <code>libcore</code> <code>#[inline]</code></p>



<a name="175523637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523637">(Sep 12 2019 at 12:29)</a>:</h4>
<p>These methods don't use the static data for anything, and LLVM removes it</p>



<a name="175523742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523742">(Sep 12 2019 at 12:30)</a>:</h4>
<p>Inlining's not main/only point though, it also has to actually ignore the panic hook (which can be set dynamically and do anything with the PanicInfo).</p>



<a name="175523779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523779">(Sep 12 2019 at 12:31)</a>:</h4>
<p>You can't just <code>#[inline]</code> it and let it call the hook and get the code size benefits because LLVM can't know what the panic hook does.</p>



<a name="175523919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523919">(Sep 12 2019 at 12:33)</a>:</h4>
<p>I did not know that it could be set dynamically.</p>



<a name="175523935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175523935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175523935">(Sep 12 2019 at 12:33)</a>:</h4>
<p>I thought that the <code>panic_impl</code> lang item just dispatched to <code>#[panic_handler]</code></p>



<a name="175524013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524013">(Sep 12 2019 at 12:34)</a>:</h4>
<p>How the panic is eventually resolved (aborting, unwinding, etc.) is decided by the panic_handler. The panic_hook gets to look at the panic message and decide to print it (default), log it, silently swallow it, etc.</p>



<a name="175524134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524134">(Sep 12 2019 at 12:36)</a>:</h4>
<p>Wait no, that's not quite right</p>



<a name="175524240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524240">(Sep 12 2019 at 12:37)</a>:</h4>
<p>Oh nvm it is, I was just looking at the wrong part of <a href="http://panicking.rs" target="_blank" title="http://panicking.rs">panicking.rs</a></p>



<a name="175524299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524299">(Sep 12 2019 at 12:38)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nomicon/panic-handler.html" target="_blank" title="https://doc.rust-lang.org/nomicon/panic-handler.html">https://doc.rust-lang.org/nomicon/panic-handler.html</a></p>



<a name="175524317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524317">(Sep 12 2019 at 12:38)</a>:</h4>
<p>That says that such a function must only appear once in the dependency graph of a crate</p>



<a name="175524332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524332">(Sep 12 2019 at 12:38)</a>:</h4>
<p>I think that the methods in <code>panicking.rs</code> just import the symbol using <code>extern "Rust" { ... }</code></p>



<a name="175524362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524362">(Sep 12 2019 at 12:39)</a>:</h4>
<p>I think that without LTO you are right in that it inlining the functions of panicking wouldn't be enough</p>



<a name="175524390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524390">(Sep 12 2019 at 12:39)</a>:</h4>
<p>but I would hope that LTO would inline the <code>#[panic_handler]</code> there</p>



<a name="175524454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524454">(Sep 12 2019 at 12:40)</a>:</h4>
<p>and if the panic handler doesn't use the panic message for anything, that the panic messages are discarded</p>



<a name="175524494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524494">(Sep 12 2019 at 12:41)</a>:</h4>
<p>Ah wait, this exists: <a href="https://doc.rust-lang.org/std/panic/fn.set_hook.html" target="_blank" title="https://doc.rust-lang.org/std/panic/fn.set_hook.html">https://doc.rust-lang.org/std/panic/fn.set_hook.html</a></p>



<a name="175524577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524577">(Sep 12 2019 at 12:42)</a>:</h4>
<p>Ohhhhhhhh</p>



<a name="175524584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524584">(Sep 12 2019 at 12:42)</a>:</h4>
<p>I mixed up panic_handler and panic_runtime</p>



<a name="175524601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524601">(Sep 12 2019 at 12:43)</a>:</h4>
<p>I thought I knew how this worked, but now I'm confused. Is there a summary somewhere explaining how this works ?</p>



<a name="175524616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524616">(Sep 12 2019 at 12:43)</a>:</h4>
<p>panic_handler is only available for applications that don't link in libstd anywhere and allows bypassing the hook (which doesn't exist at all w/o std) and other infrastructure.</p>



<a name="175524641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524641">(Sep 12 2019 at 12:43)</a>:</h4>
<p>So when is the hook called ?</p>



<a name="175524645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524645">(Sep 12 2019 at 12:43)</a>:</h4>
<p>panic runtime is what allows customizing abort/unwind/etc. in an application using libstd, but can't bypass the panic hook</p>



<a name="175524698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524698">(Sep 12 2019 at 12:44)</a>:</h4>
<p>That should be this: <a href="https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libpanic_abort/lib.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libpanic_abort/lib.rs">https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libpanic_abort/lib.rs</a></p>



<a name="175524711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524711">(Sep 12 2019 at 12:44)</a>:</h4>
<p>(for the abort run-time)</p>



<a name="175524726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524726">(Sep 12 2019 at 12:44)</a>:</h4>
<p>I'm reluctant to answer because I was so wrong before, but AFAIK: the hook is called in libstd's panic_handler, <em>before</em> entering the panic runtime (what you linked, for panic=abort)</p>



<a name="175524858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524858">(Sep 12 2019 at 12:46)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libstd/panicking.rs#L381" target="_blank" title="https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libstd/panicking.rs#L381">https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libstd/panicking.rs#L381</a></p>



<a name="175524869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524869">(Sep 12 2019 at 12:46)</a>:</h4>
<p>I think now I get it, the hook is called there</p>



<a name="175524903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524903">(Sep 12 2019 at 12:47)</a>:</h4>
<p>So to get back to the original topic, a custom <code>panic_handler</code> that ignores the &amp;PanicInfo argument gets you all the code size benefits (with LTO), but you can't do that if libstd is present anywhere in your application.</p>



<a name="175524916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175524916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175524916">(Sep 12 2019 at 12:47)</a>:</h4>
<p>Yes, that sounds about right.</p>



<a name="175525033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525033">(Sep 12 2019 at 12:48)</a>:</h4>
<p>libstd also has the same cargo feature as libcore, to opt out of this</p>



<a name="175525159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525159">(Sep 12 2019 at 12:50)</a>:</h4>
<p>I wonder why libstd needs to keep track of the panic count</p>



<a name="175525176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525176">(Sep 12 2019 at 12:50)</a>:</h4>
<p>I thought this would be done in the panic run-time itself</p>



<a name="175525203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525203">(Sep 12 2019 at 12:51)</a>:</h4>
<p>idk</p>



<a name="175525204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525204">(Sep 12 2019 at 12:51)</a>:</h4>
<p>Maybe historical cruft</p>



<a name="175525218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525218">(Sep 12 2019 at 12:51)</a>:</h4>
<p>Like, i can't find a panic count in libcore</p>



<a name="175525286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525286">(Sep 12 2019 at 12:52)</a>:</h4>
<p>But I'd expect that to be required to detect double panics</p>



<a name="175525448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525448">(Sep 12 2019 at 12:54)</a>:</h4>
<p>maybe that's handled by libunwind</p>



<a name="175525461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525461">(Sep 12 2019 at 12:54)</a>:</h4>
<p>Unwinding requires libstd anyway I think</p>



<a name="175525483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525483">(Sep 12 2019 at 12:54)</a>:</h4>
<p>I mean, going without libstd and defining a panic_handler that unwinds is entirely unsupported</p>



<a name="175525534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525534">(Sep 12 2019 at 12:55)</a>:</h4>
<p>The only supported unwinding is the panic=unwind runtime and that's a runtime, not a handler, so you'll only get it by using libstd</p>



<a name="175525802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Bound%20checks%20abort/near/175525802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Bound.20checks.20abort.html#175525802">(Sep 12 2019 at 12:59)</a>:</h4>
<p>Ah that explains it. I thought that one could build a <code>#![no_std]</code> binary not only with <code>-C panic=abort</code> but also wit h<code>-C panic=unwind</code> by only linking the libpanic_unwind crate, and not libstd</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>